package com.topsun.protocol.server;

import com.topsun.protocol.server.codec.MyMessageDecoder;
import com.topsun.protocol.server.codec.MyMessageEncoder;
import com.topsun.protocol.server.core.DefaultHandlerMapping;
import com.topsun.protocol.server.endpoint.MyHandlerInterceptor;
import com.topsun.protocol.server.handler.DispatcherHandler;
import com.topsun.protocol.server.session.SessionManager;

import java.nio.charset.StandardCharsets;


public class QuickStart {

    public static final int port = 7611;

    public static void main(String[] args) {
//        DispatcherHandler.STOPWATCH = true;

        Server udpServer = new NettyConfig.Builder()
                .setPort(port)
//                .setThreadGroup(0, 1)
                .setDelimiters(new byte[][]{"|".getBytes(StandardCharsets.UTF_8)})
                .setDecoder(new MyMessageDecoder())
                .setEncoder(new MyMessageEncoder())
                .setHandlerMapping(new DefaultHandlerMapping("com.topsun.protocol.server.endpoint"))
                .setHandlerInterceptor(new MyHandlerInterceptor())
                .setSessionManager(new SessionManager())
                .setEnableUDP(true)
                .build();
        udpServer.start();

        Server tcpServer = new NettyConfig.Builder()
                .setPort(port)
                .setMaxFrameLength(2048)
                .setDelimiters(new byte[][]{"|".getBytes(StandardCharsets.UTF_8)})
                .setDecoder(new MyMessageDecoder())
                .setEncoder(new MyMessageEncoder())
                .setHandlerMapping(new DefaultHandlerMapping("com.topsun.protocol.server.endpoint"))
                .setHandlerInterceptor(new MyHandlerInterceptor())
                .setSessionManager(new SessionManager())
                .build();
        tcpServer.start();
    }
}